﻿package Server.AHMJ.HQMJ;

import org.json.JSONObject;

public class CMD_Maj {

}

class IJsonExport {
	public String toString() {
		return getJsonData();
	}

	private String getJsonData() {
		return "";
	}

	public static String sprintf_BYTE(int by[][], int count) {

		int tmpCardData[] = new int[count]; // 用户扑克
		for (int i = 0; i < by.length; i++) {
			for (int k = 0; k < by[i].length; k++) {
				tmpCardData[i * by[i].length + k] = by[i][k];
			}
		}
		String strCardData = sprintf_BYTE(tmpCardData, count);
		return strCardData;
	}

	public static String sprintf_BYTE(Integer by[][], int count) {

		int tmpCardData[] = new int[count]; // 用户扑克
		for (int i = 0; i < by.length; i++) {
			for (int k = 0; k < by[i].length; k++) {
				tmpCardData[i * by[i].length + k] = by[i][k];
			}
		}
		String strCardData = sprintf_BYTE(tmpCardData, count);
		return strCardData;
	}

	public static String sprintf_BYTE(Integer by[], int count) {
		return sprintf_INT32(by, count);
	}

	public static String sprintf_BYTE(int by[], int count) {
		return sprintf_INT32(by, count);
	}

	public static String sprintf_DWORD(int dw[], int count) {
		return sprintf_INT32(dw, count);
	}

	public static String sprintf_INT32(Integer dw[], int count) {
		if (count < 1) {
			return "";
		}
		StringBuffer out_str = new StringBuffer();
		out_str.append(dw[0]);
		for (int i = 1; i < count; i++) {
			out_str.append(",");
			out_str.append(dw[i]);
		}
		return out_str.toString();
	}

	public static String sprintf_INT32(int dw[], int count) {
		if (count < 1) {
			return "";
		}
		StringBuffer out_str = new StringBuffer();
		out_str.append(dw[0]);
		for (int i = 1; i < count; i++) {
			out_str.append(",");
			out_str.append(dw[i]);
		}
		return out_str.toString();
	}
}

/***
 * 玩家请求进入房间
 */
class SUBCMD_S_Connect extends IJsonExport {

	int m_lUid;

	String getJsonData() {
		String mjmsg = String.format("connect|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_Join extends IJsonExport {

	int m_lUid;

	String getJsonData() {

		String mjmsg = String.format("join|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

// 离开房间通知
class SUBCMD_S_Leave extends IJsonExport {

	int m_lUid;// 玩家ID

	String getJsonData() {

		String mjmsg = String.format("leave|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

// 离开房间通知
class SUBCMD_S_Offline extends IJsonExport {

	int m_lUid;// 玩家ID

	String getJsonData() {

		String mjmsg = String.format("offline|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_CreateRoom extends IJsonExport {

	int cbResult;
	int cbRound;
	short m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String mjmsg = String.format("createroom|%d|%d|%d|%d", cbResult, cbRound, m_wUserChairID, m_dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_Param extends IJsonExport {

	int m_dwTableID;// 房间ID
	String szParam;
	String szRoomDesc;
	
	String getJsonData() {

		String mjmsg = String.format("param|%d|%s|%s", m_dwTableID,szParam,szRoomDesc);

		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};

class SUBCMD_S_TryDismissRoom extends IJsonExport {

	long lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String mjmsg = String.format("try_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_AgreeDismissRoom extends IJsonExport {

	long lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String mjmsg = String.format("agree_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_RefuseDismissRoom extends IJsonExport {

	long lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String mjmsg = String.format("refuse_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_DismissRoom extends IJsonExport {

	int cbResult;
	long lUid;
	short m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String mjmsg = String.format("dismissroom|%d|%d|%d|%d", cbResult, lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_JoinRoom extends IJsonExport {

	int lUid;
	int cbResult;
	int dwTableID;// 房间ID
	int cbRound;
	String strParam;
	String szGameName;
	String szGameDesc;

	String getJsonData() {


		String mjmsg = String.format("joinroom|%d|%d|%d|%d|%s|%s|%s", lUid, cbResult, dwTableID, cbRound, strParam,
				szGameName, szGameDesc);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_AvatarURL extends IJsonExport {

	long lUid;
	String szURL;

	String getJsonData() {

		String mjmsg = String.format("avatar|%d|%s", lUid, szURL);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_Sit extends IJsonExport {

	int m_lUid;
	int m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID
	int m_lUserScore;
	String szNickName;
	int m_cbGender;
	int m_iAvatar;
	String szIP;

	String getJsonData() {
		String mjmsg = String.format("sit|%d|%d|%d|%d|%s|%d|%d|%s", m_lUid, m_wUserChairID, m_dwTableID, m_lUserScore,
				szNickName, m_cbGender, m_iAvatar, szIP);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_DenySit extends IJsonExport {

	int cbReason; // 1,没有找到房间,2，房间已满

	String getJsonData() {

		String mjmsg = String.format("denysit|%d", cbReason);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_Look extends IJsonExport {

	int m_lUid;
	short m_wUserChairID;// 房间ID
	int m_iTotalCoin;
	String szNickName;

	String getJsonData() {

		String mjmsg = String.format("look|%d|%d|%d|%d|%s", m_lUid, m_wUserChairID, m_iTotalCoin, szNickName);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_StandUp extends IJsonExport {

	int m_lUid;// 玩家ID
	int m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String mjmsg = String.format("standup|%d|%d|%d", m_lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_Kick extends IJsonExport {

	int m_lUid;// 玩家ID
	int m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String mjmsg = String.format("kick|%d|%d|%d", m_lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};
class SUBCMD_S_Number extends IJsonExport {
    Integer number;
	String getJsonData() {

		String mjmsg = String.format("number|%d",number);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};


class SUBCMD_S_Ready extends IJsonExport {

	int m_lUid;// 玩家ID
	int m_wUserChairID;// 玩家座位
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String mjmsg = String.format("ready|%d|%d|%d", m_lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

// 聊天表情
class SUBCMD_S_BiaoQing extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位
	int m_iBiaoQingIndex;

	String getJsonData() {

		String mjmsg = String.format("biaoqing|%d|%d|%d", m_lUid, m_wUserChairID, m_iBiaoQingIndex);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};
//鸡蛋
class SUBCMD_S_Gift extends IJsonExport {
	int fromSide;// 发送的人
	int toSide;// 接受的的人
	int index;//发送的道具

	String getJsonData() {

		String mjmsg = String.format("gift|%d|%d|%d",fromSide,toSide,index);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};
// 语音
class SUBCMD_S_YuYin extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	int m_iYuYinIndex;

	String getJsonData() {

		String mjmsg = String.format("yuyin|%d|%d|%d", m_lUid, m_wUserChairID, m_iYuYinIndex);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

// 语音
class SUBCMD_S_Avatar extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	String szAvatarURL;

	String getJsonData() {

		String mjmsg = String.format("avatar|%d|%s", m_lUid, szAvatarURL);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

// 语音
class SUBCMD_S_Chat extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	String szContent;

	String getJsonData() {

		String mjmsg = String.format("chat|%d|%d|%s", m_lUid, m_wUserChairID, szContent);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

// 语音
class SUBCMD_S_Voice extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	int seconds;
	String szVoiceURL;

	String getJsonData() {

		String mjmsg = String.format("voice|%d|%d|%d|%s", m_lUid, m_wUserChairID, seconds, szVoiceURL);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};
//语音新
class SUBCMD_S_VoiceMsg extends IJsonExport{
	int m_lUid;
	int m_wUserChairID;
	int m_maxClip;
	int m_currClip;
	float seconds;
	String data;
	
	String getJsonData() {

		String mjmsg = String.format("voicemsg|%d|%d|%f|%s|%d|%d", m_lUid, m_wUserChairID, seconds, data,m_maxClip,m_currClip);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

// 送礼
class SUBCMD_S_SongLi extends IJsonExport {
	int m_srcUid;// 哪个玩家ID获得
	int m_dstUid;// 玩家座位 号
	int m_iLiWu;
	int m_srcCoin;// 送礼的人余下多少钱
	int m_dstCoin;// 收礼的人余下多少钱

	String getJsonData() {

		String mjmsg = String.format("use|%d|%d|%d|%d|%d", m_srcUid, m_dstUid, m_iLiWu, m_srcCoin, m_dstCoin);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_Error extends IJsonExport {
	int byRound;// 玩家ID
	int bySeatID;// 玩家座位
	int errCode;// 玩家座位
	String errMsg;// 房间ID

	String getJsonData() {

		String sszmsg = String.format("error|%d|%d|%d|%s", byRound, bySeatID,errCode, errMsg);
		JSONObject json = new JSONObject();
		json.put("command", "sszmsg");
		json.put("sszmsg", sszmsg);

		return json.toString();
	}
};

class SSeatInfo {
	int m_lUid;// UID
	int m_lTotalCoin;// COIN
	String m_NickName = "";// NICKNAME
	long m_lBetCoin;//
	int m_cbGender;//
	long m_iAvatar;//
	int m_cbUserStatus;// 用户状态
	int m_iVipLevel;// VIP LEVEL
	int m_iTitle;// 称号
	int m_isLookon;// 是否观众
	String szIP = "";
	public int m_iBetCoin;
	
	
	
	int  m_iSeatId;//座位号ID	
	int  m_iTotalCoin;//COIN	

	public String toString(){
		String mjmsg = String.format( "%d#%d#%d#%s#%d#%d#%d#%d#%d#%d#%d#%s", m_lUid, m_iSeatId, m_iTotalCoin, m_NickName, m_iBetCoin, m_cbGender, m_iAvatar, m_cbUserStatus, m_iVipLevel, m_iTitle, m_isLookon, szIP);
		return mjmsg ;      
	}  
};

class SUBCMD_S_Table extends IJsonExport { // 同步房间玩家信息
	int m_dwTableID;// 房间ID
	long m_lCellScore;
	int m_bTableStarted;// 只要开始玩
	long m_byRound;//
	long m_byMaxRound;//
	int m_bGameStarted;// 游戏开始
	int m_cntLookon;// 观众数量
	String m_roomDesc;
	SSeatInfo m_seatInfo[] = new SSeatInfo[4];
	String vecInputWenZi;
	public int m_byYuPai;
	{
		for (int i = 0; i < m_seatInfo.length; i++) {
			m_seatInfo[i] = new SSeatInfo();
		}
		m_dwTableID = 0;
		m_lCellScore = 1L;
		m_bTableStarted = 1;// 只要开始玩
		m_byRound = 1L;//
		m_byMaxRound = 8L;//
		m_bGameStarted = 0;// 游戏开始
		m_cntLookon = 0;// 观众数量
	}

	String getJsonData() {

		String mjmsg = String.format("table|%d|%d|%d|%d|%d|%d|%d|%s|%s|%s|%s|%s|%s", m_dwTableID,m_bTableStarted,m_byYuPai,m_byRound,m_byMaxRound,m_bGameStarted,m_cntLookon, m_seatInfo[0].toString(),
				m_seatInfo[1].toString(), m_seatInfo[2].toString(), m_seatInfo[3].toString(),m_roomDesc,vecInputWenZi);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

// 用户出牌
class SUBCMD_S_TableBegin extends IJsonExport {
	String strParam;
	int byZhuang;
	long byRound;//
	long byMaxRound;
	int byYuPai;//
	int byCurrentUser;
	int lScore[] = new int[4];
	int lRoundScore[] = new int[4];
	int byLastOutMj;
	int byGuiPai[] = new int[2];
	int byLianZhuang;
	int m_LastSeatId;

	String getJsonData() {
		String strScore = sprintf_INT32(lScore, 4);
		String strRoundScore = sprintf_INT32(lRoundScore, 4);
		String strGuiPai = sprintf_INT32(byGuiPai, 2);
		
		String mjmsg = String.format("table_begin|%s|%d|%d|%d|%d|%d|%s|%s|%d|%s|%d|%d", strParam, byZhuang, byRound,
				byMaxRound, byYuPai, byCurrentUser, strScore, strRoundScore, byLastOutMj, strGuiPai,byLianZhuang,m_LastSeatId);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};

// 用户出牌
class SUBCMD_S_TableSide extends IJsonExport {
	int bySeatID;
	int byTing;
	int byBaoZi;
	int Maj[] = new int[Constants.HAND_MJ_MAX];
	int Hua[] = new int[8];
	HU hu = new HU();
	int outMj[] = new int[20];
	int byRight[] = new int[6];// 吃碰杠听胡权限
	int byKeHuPai[] = new int[13];
	int byKouPai[] = new int[4];

	String getJsonData() {

		String strMaj = sprintf_BYTE(Maj, Constants.HAND_MJ_MAX);
		String strHua = sprintf_BYTE(Hua, 8);

		String szHu = String.format("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", hu.jiangMj, 
				hu.block[0].style, hu.block[0].first, hu.block[0].origValue,
				hu.block[1].style, hu.block[1].first, hu.block[1].origValue,
				hu.block[2].style, hu.block[2].first, hu.block[2].origValue,
				hu.block[3].style, hu.block[3].first, hu.block[3].origValue);
		String strOutMj = sprintf_BYTE(outMj, 20);
		String strOpRight = sprintf_BYTE(byRight, 6);
		
		int cntKeHuPai = 0;
		for(int i=0;i<13;i++)
		{
			if(MajHelper.IsWTSZ(byKeHuPai[i]))
			{
				cntKeHuPai++;
			}
		}
		String strKeHuPai = sprintf_BYTE(byKeHuPai, cntKeHuPai);
		int cntKouPai = 0;
		for(int i=0;i<4;i++)
		{
			if(MajHelper.IsWTSZ(byKouPai[i]))
			{
				cntKouPai++;
			}
		}
		String strKouPai = sprintf_BYTE(byKouPai, cntKouPai);
		
		String mjmsg = String.format("table_side|%d|%d|%s|%s|%s|%s|%s|%s|%d", bySeatID, byTing, strMaj, strHua, szHu,
				strOutMj, strOpRight,strKeHuPai,byBaoZi);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		
		return json.toString();
	}
};

// 用户出牌
class SUBCMD_S_TableEnd extends IJsonExport {
	int cbSceneStatus;

	String getJsonData() {

		String mjmsg = String.format("table_end|%d", cbSceneStatus);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

//用户出牌
class SUBCMD_S_KouPai extends IJsonExport {
	int byRound;
	int byKouPai[][] = new int[4][4];

	String getJsonData() {

		String strKouPai0 = sprintf_BYTE(byKouPai[0], 4);
		String strKouPai1 = sprintf_BYTE(byKouPai[1], 4);
		String strKouPai2 = sprintf_BYTE(byKouPai[2], 4);
		String strKouPai3 = sprintf_BYTE(byKouPai[3], 4);
		
		String mjmsg = String.format("koupai|%d|%s|%s|%s|%s", byRound, strKouPai0, strKouPai1, strKouPai2, strKouPai3);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};


// 用户出牌
class SUBCMD_S_YuPai extends IJsonExport {
	int byYuPai;
	int byCurrentUser;

	String getJsonData() {

		String mjmsg = String.format("yupai|%d|%d", byYuPai, byCurrentUser);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};

// 用户出牌
class SUBCMD_S_FaPai extends IJsonExport {
	int byRound;
	int byZhuang;
	int byLianZhuang;
	int byMaxRound;
	int byMj[] = new int[Constants.HAND_MJ_MAX];
	int byGuiPai[] = new int[2];
	int lastZhuang;

	String getJsonData() {
		String strMj0 = sprintf_INT32(byMj, Constants.HAND_MJ_MAX);

		int cntGuiPai = 0;
		for(int i=0;i<2;i++)
		{
			if(MajHelper.IsWTSZ(byGuiPai[i]))
			{
				cntGuiPai++;
			}
		}
		
		String strGuiPai = "";
		if(cntGuiPai > 0)
		{
			strGuiPai = sprintf_INT32(byGuiPai, cntGuiPai);
		}

		String mjmsg = String.format("fapai|%d|%d|%d|%d|%s|%s|%d", byRound, byZhuang, byLianZhuang, byMaxRound, strMj0,strGuiPai,lastZhuang);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		
		return json.toString();
	}
};

// 摸牌: mopai|reason|bySeatID|byMj|0,0,bGang,bTing,bHu
class SUBCMD_S_MoPai extends IJsonExport {
	int reason; // 普通摸牌，或者杠上开花
	int byMoPai; // 摸牌
	int bySeatID; // 当前玩家
	int bTing; // 是否能听牌
	int nHu; // 是否能胡牌
	int nGang; // 是否自摸杠
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];

	String getJsonData() {
		String strHandMj = sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);
		String mjmsg = String.format("mopai|%d|%d|%d|0,0,%d,%d,%d|%s", reason, bySeatID, byMoPai, nGang, bTing, nHu,strHandMj);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};

// 出牌:
// chupai|bySeatID|byMj|bAllowChi,bAllowPeng,bAllowGang,0,bAllowHu|byTing|byKeHuPai
class SUBCMD_S_ChuPai extends IJsonExport {
	int byActionUser; // 出牌玩家
	int byOutMj; // 打出的牌
	int bChi; // 能否吃
	int bPeng; // 能否碰
	int bGang; // 能否杠
	int bHu; // 能否胡
	int byTingPos; // 听牌POS
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];

	// 权限,5-胡,3-杠,2-碰,1-吃
	String getJsonData() {

		String strHandMj = sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);

		String mjmsg = String.format("chupai|%d|%d|%d,%d,%d,0,%d|%d|%s", byActionUser, byOutMj, bChi, bPeng, bGang,
				bHu, byTingPos, strHandMj);

		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};

// 补花
class SUBCMD_S_BuHua extends IJsonExport {
	int byHua; // 补花
};

// 吃牌:
// chipai|bySeatID|byOutMjSeatID|byChiMj|block.style,block.first|byChiMode|byTing|byHandMj
class SUBCMD_S_Chi extends IJsonExport {
	int byActionUser; // 操作玩家
	int byOutMjUser; // 出牌玩家
	int byMj; // 吃牌
	BLOCK block = new BLOCK(); // 吃牌块
	int nChiType; // 吃牌类型,0-无,1-@@*, 2-@*@, 4-*@@
	int byTingRight; // 听牌的权限
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];
	int isMingpai; // 是否明牌
	int canGang;
	String getJsonData() {

		String strHandMj = sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);
		String mjmsg = String.format("chipai|%d|%d|%d|%d,%d,%d|%d,|%d|%s|%d|%d", byActionUser, byOutMjUser, byMj, block.style,
				block.first,block.origValue,nChiType, byTingRight, strHandMj,isMingpai,canGang);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};

// 吃牌选择
class SUBCMD_S_ChiMode extends IJsonExport {
	int nChiType;// 吃牌类型
};

// 碰牌
class SUBCMD_S_Peng extends IJsonExport {
	int byActionUser; // 操作玩家
	int byOutMjUser;// 出牌玩家
	int byMj; // 吃牌
	BLOCK block = new BLOCK(); // 胡牌块着张
	int byTingRight; // 听牌的权限
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];
	int isMingpai; // 是否明牌
	int canGang = 0;

	String getJsonData() {

		String strHandMj = sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);
		String mjmsg = String.format("pengpai|%d|%d|%d|%d,%d,%d|%d|%d|%s|%d|%d", byActionUser, byOutMjUser, byMj, block.style,
				block.first,block.origValue, 0, byTingRight, strHandMj,isMingpai,canGang);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};
class SUBCMD_S_BaoZi extends IJsonExport{
	int byActionUser;
	
	String getJsonData(){
		String mjmsg = String.format("baozi|%d", byActionUser);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
}
class SUBCMD_S_InBack extends IJsonExport{
	int byActionUser;
	String getJsonData(){
		String mjmsg = String.format("inBack|%d", byActionUser);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
}
class SUBCMD_S_InFore extends IJsonExport{
	int byActionUser;
	String getJsonData(){
		String mjmsg = String.format("inFore|%d", byActionUser);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
}
class SUBCMD_S_Ting extends IJsonExport {
	int byActionUser;

	
	String getJsonData() {

		String mjmsg = String.format("ting|%d", byActionUser);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};

class SUBCMD_S_MingPai extends IJsonExport {
	int bySeatID;
	int cntBuLiang;
	int byLiangMj[] = new int[Constants.HAND_MJ_MAX];
	int byKeHuPai[] = new int[Constants.HAND_MJ_MAX];
	
	String getJsonData() {
		String strHandMj = sprintf_BYTE(byLiangMj, Constants.HAND_MJ_MAX);
		
		int cntKeHuPai = 0;
		for(int i=0;i<Constants.HAND_MJ_MAX;i++)
		{
			if(MajHelper.IsWTSZ(byKeHuPai[i]))
			{
				cntKeHuPai++;
			}
		}
		String strKeHuPai = sprintf_BYTE(byKeHuPai, cntKeHuPai);
		
		String mjmsg = String.format("mingpai|%d|%d|%s|%s", bySeatID,cntBuLiang,strHandMj,strKeHuPai);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};


// 杠牌选择
class SUBCMD_S_GangMode extends IJsonExport {
	int byMjGang[] = new int[4]; // 可杠的牌
	int nGangMode;// 杠牌类型
};

// 杠牌
class SUBCMD_S_Gang extends IJsonExport {
	int byActionUser; // 操作玩家
	int byOutMjUser; // 出牌玩家
	int byMj; // 吃牌
	BLOCK block = new BLOCK(); // 胡牌块着张
	int gangType;// 杠牌类型,1-明,2-补,4-暗
	int byBuMj; // 这个功能不做
	int bTing; // 是否能听牌
	int bHu[] = new int[4]; // 抢杠胡
	int bZiMoGang; // 是否自摸杠
	int byHandMj[] = new int[Constants.HAND_MJ_MAX];
	int bQiangHu;
	int isMingpai; // 是否明牌

	String getJsonData() {

		String strHandMj = sprintf_BYTE(byHandMj, Constants.HAND_MJ_MAX);
		String mjmsg = String.format("gangpai|%d|%d|%d|%d,%d,%d|%d|%d|%d|%d,%d,%d,%d|%d|%s|%d|%d", byActionUser, byOutMjUser,
				byMj, block.style, block.first,block.origValue, gangType, byBuMj, bTing, bHu[0], bHu[1], bHu[2], bHu[3], bZiMoGang,
				strHandMj,bQiangHu,isMingpai);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};

class SUBCMD_S_HU extends IJsonExport {
	int byWinner; // 赢家
	int byFangQiang; // 有没有放枪的人
	int byHuMj;
	int winScore[] = new int[4];
	int resultScore[] = new int[4];

	String getJsonData() {

		String strWinScore = sprintf_INT32(winScore, 4);
		String strResultScore = sprintf_INT32(resultScore, 4);
		String mjmsg = String.format("hupai|%d|%d|%d|%s|%s", byWinner, byFangQiang, byHuMj, strWinScore,
				strResultScore);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};

class SUBCMD_S_KeHuPai extends IJsonExport {
	int byRound;
	int vecKeHuPai[][] = new int[4][13];
	String getJsonData()
	{
		String strKeHuPai0 = "";String strKeHuPai1="";String strKeHuPai2 = "";String strKeHuPai3="";
		for(int i=0;i<4;i++)
		{
			int cntKeHuPai = 0;
			for(int j =0;j<13;j++)
			{
				if(MajHelper.IsWTSZ(vecKeHuPai[i][j]))
				{
					cntKeHuPai++;
				}
			}
			if(i == 0)
			{
				strKeHuPai0 = sprintf_INT32(vecKeHuPai[i], cntKeHuPai);
			}
			if(i == 1)
			{
				strKeHuPai1 = sprintf_INT32(vecKeHuPai[i], cntKeHuPai);
			}
			if(i == 2)
			{
				strKeHuPai2 = sprintf_INT32(vecKeHuPai[i], cntKeHuPai);
			}
			if(i == 3)
			{
				strKeHuPai3 = sprintf_INT32(vecKeHuPai[i], cntKeHuPai);
			}
		}
		
		String mjmsg = String.format("kehupai|%d|%s|%s|%s|%s", byRound,strKeHuPai0,strKeHuPai1,strKeHuPai2,strKeHuPai3);
		
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		
		return json.toString();
	}
};


class SUBCMD_S_MoMa extends IJsonExport {
	int vecMaPai[] = new int[6];
	String getJsonData()
	{
		String strMaPai = sprintf_INT32(vecMaPai, 6);
		
		String mjmsg = String.format("moma|%s", strMaPai);
		
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		
		return json.toString();
	}
};

class tagJieSuan {
	int lRoundScore;
	String  strHuType;
	int byHandMj[] = new int[14];
	HU hu = new HU();

	public String toString() {
		String szHu = String.format("%d,%d,%d,%d,%d,%d,%d,%d,%d", hu.jiangMj, hu.block[0].style, hu.block[0].first,
				hu.block[1].style, hu.block[1].first, hu.block[2].style, hu.block[2].first, hu.block[3].style,
				hu.block[3].first);

		String strHandMj = IJsonExport.sprintf_BYTE(byHandMj, 14);
		String mjmsg = String.format("%d#%s#%s#%s", lRoundScore,strHuType, strHandMj, szHu);
		return mjmsg;
	}
};

class SUBCMD_S_JIESUAN extends IJsonExport {
	long byRound; //
	int byZhuang; //
	int byLianZhuang;
	tagJieSuan userJieSuan[] = new tagJieSuan[4];
	
	int winScore[] = new int[4];
	int resultScore[] = new int[4];
	
	{
		for (int i = 0; i < userJieSuan.length; i++) {
			userJieSuan[i] = new tagJieSuan();
		}
	}

	String getJsonData() {

		String strJieSuan0 = userJieSuan[0].toString();
		String strJieSuan1 = userJieSuan[1].toString();
		String strJieSuan2 = userJieSuan[2].toString();
		String strJieSuan3 = userJieSuan[3].toString();
		
		String strWinScore = sprintf_INT32(winScore, 4);
		String strResultScore = sprintf_INT32(resultScore, 4);
		

		String mjmsg = String.format("jiesuan|%d|%d|%d|%s|%s|%s|%s|%s|%s", byRound, byZhuang, byLianZhuang, strJieSuan0,
				strJieSuan1, strJieSuan2, strJieSuan3,strWinScore,strResultScore);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};

class tagUserReport {
	int lUid;
	/**
	 * 自模糊
	 */
	int cntZiMo;
	/**
	 * 胡的总次数
	 */
	int cntHu;
	/**
	 * 点炮的次数
	 */
	int cntDianPao;
	/**
	 * 用于统计补杠和明杠
	 */
	int cntGang;
	int cntDianGang;
	int lWinScore;
	int lLoseScore;
	int lResultScore;
	/**
	 * 用于统计暗杠
	 */
	int cntAnGang;
	/**
	 * 用于统计点炮胡
	 */
    int dianPaoHu;
    
	public String toString() {
		String data = String.format("%d#%d#%d#%d#%d#%d#%d#%d#%d#%d#%d", lUid, cntZiMo, cntHu, cntDianPao,cntGang, lWinScore, lLoseScore,
				lResultScore,cntDianGang,cntAnGang,dianPaoHu);

		return data;
	}
};

class SUBCMD_S_REPORT extends IJsonExport {
	int cbReason;
	int cbType;
	tagUserReport userReport[] = new tagUserReport[4] ;
	{
		for (int i = 0; i < userReport.length; i++) {
			userReport[i] = new tagUserReport();
		}
	}
	String getJsonData() {

		String sReport0 = userReport[0].toString();
		String sReport1 = userReport[1].toString();
		String sReport2 = userReport[2].toString();
		String sReport3 = userReport[3].toString();
		String mjmsg = String.format("report|%d|%d|%s|%s|%s|%s", cbReason, cbType, sReport0, sReport1, sReport2,
				sReport3);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}

};

// 不能出亮牌胡的牌
class SUBCMD_C_BuXuChuPai extends IJsonExport {
	int byOutMj;

	String getJsonData() {
		String mjmsg = String.format("buxu_chupai|%d", byOutMj);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};

class SUBCMD_C_BuXuHuPai extends IJsonExport {
	int byOutMj;
	String strReason;
	String getJsonData() {
		String mjmsg = String.format("buxu_hupai|%d|%s", byOutMj,strReason);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};
/*
class SUBCMD_S_REPORT extends IJsonExport {
	int cbReason;
	int cbType;
	int vecMaxWinScore[] = new int[5];
	int vecWinScore[] = new int[5];
	int vecLoseScore[] = new int[5];
	int vecResultScore[] = new int[5];

	String getJsonData() {

		String strMaxWinScore = Arrays.toString(vecMaxWinScore);
		strMaxWinScore = strMaxWinScore.substring(1, strMaxWinScore.length() - 1);

		String strWinScore = Arrays.toString(vecWinScore);
		strWinScore = strWinScore.substring(1, strWinScore.length() - 1);

		String strLoseScore = Arrays.toString(vecLoseScore);
		strLoseScore = strLoseScore.substring(1, strLoseScore.length() - 1);

		String strResultScore = Arrays.toString(vecResultScore);
		strResultScore = strResultScore.substring(1, strResultScore.length() - 1);

		String mjmsg = String.format("report|%d|%d|%s|%s|%s|%s", cbReason, cbType, strMaxWinScore, strWinScore,
				strLoseScore, strResultScore);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};
*/
/*
// 游戏结束
class SUBCMD_S_JieSuan extends IJsonExport {
	int m_winnerSeat;
	long lTax; // 游戏税收
	long nGameGold[] = new long[5]; // 游戏得分
	long nUserScore[] = new long[5]; // 玩家得分

	String getJsonData() {
		String strGameGold = Arrays.toString(nGameGold);
		strGameGold = strGameGold.substring(1, strGameGold.length() - 1);

		String strUserScore = Arrays.toString(nUserScore);
		strUserScore = strUserScore.substring(1, strUserScore.length() - 1);

		String mjmsg = String.format("jiesuan|%d|%d|%s|%s", m_winnerSeat, lTax, strGameGold, strUserScore);
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);

		return json.toString();
	}
};
*/
// 语音
class SUBCMD_S_Text extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	String szContent;
	String InputWenZi;
	String getJsonData() {
		String mjmsg = String.format("text|%d|%d|%s|%s", m_lUid, m_wUserChairID, szContent,InputWenZi);

		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};
// ip gps 检查
class SUBCMD_S_IpCheck extends IJsonExport {
	int m_seat1;
	int m_seat2;
	int m_type;
	String getJsonData() {
		String mjmsg = String.format("ipcheck|%d|%d|%d", m_seat1, m_seat2, m_type);
		
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};
class SUBCMD_S_GpsDisanceLimit extends IJsonExport {
	int m_seat1;
	int m_seat2;
	String getJsonData() {
		String mjmsg = String.format("gpsCheck|%d|%d", m_seat1,m_seat2);
		
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};
class SUBCMD_S_GpsNull extends IJsonExport {
	int m_seat1;
	int m_seat2;
	int m_seat3;
	int m_seat4;
	public void addNullGps(int seat){
		if(m_seat1 < 0){
			m_seat1 = seat;
			return;
		}
		if(m_seat2 < 0){
			m_seat2 = seat;
			return;
		}
		if(m_seat3 < 0){
			m_seat3 = seat;
			return;
		}
		if(m_seat4 < 0){
			m_seat4 = seat;
			return;
		}
	}
	String getJsonData() {
		String mjmsg = String.format("gpsNull|%d|%d|%d|%d", m_seat1,m_seat2,m_seat3,m_seat4);
		
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
	public SUBCMD_S_GpsNull(){
		m_seat1 = -1;
		m_seat2 = -1;
		m_seat3 = -1;
		m_seat4 = -1;
	}
};
class SUBCMD_S_GpsOk extends IJsonExport {
	int m_seat;
	String getJsonData() {
		String mjmsg = String.format("gpsOk|%d", m_seat);
		
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};

class SUBCMD_S_GpsWarn extends IJsonExport {
	int    red_seat[] = new int[4];
	String ip_warn;
	String gps_warn;
	String getJsonData() {
		
		String strRedSeat = sprintf_INT32(red_seat, 4);
		
		String mjmsg = String.format("gps_warn|%s|%s|%s",strRedSeat, ip_warn,gps_warn);
		
		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};